package com.aaa.controller;

import com.aaa.service.L_PointSetService;
import com.aaa.util.EmpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/PointSet")
public class L_PointSet {
        @Autowired
        private L_PointSetService setService;

        @RequestMapping("/pointset")
        @ResponseBody
        public Object addSet(@RequestBody Map map){
            int id=setService.getunitID(map);
            System.out.println(id);
            map.put("id",id);
            List<Map> list=setService.cpscore(map);//查询总表里上报单位的扣分分数
            System.out.println(list.get(0)+"       原来");
            System.out.println(list.size()+"    长度");
            if (list.get(0)!=null){
                //如果存在此单位申报，就分数相加
                setService.addcpscore(map);
            }else if(list.get(0)==null){
                setService.setRegist(map);//如果不存在,给总表里添加扣分分数
            }
            Boolean boolead=setService.addSet(map);
            if (boolead){
                return  0;
            }else {
                return 1;
            }
        }

        @RequestMapping("/score")
        @ResponseBody
         public Object score(){
            Map zmap=new HashMap();
            zmap.put("options",setService.Score());
            zmap.put("content",setService.Content());
            zmap.put("unit",setService.getunit());

            System.out.println(EmpUtil.getEmp()+"      session");
            System.out.println(EmpUtil.getMessage()+"      session");
            return zmap;
        }

        @RequestMapping("chachong")
        @ResponseBody
        public Object chachong(@RequestBody Map map){
               int i=setService.chachong(map);
               return i;
           }
}
